package com.leetroll.common.validator.constraints;

import com.leetroll.common.validator.annotation.NotBlank;
import com.leetroll.common.utils.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 判断是否为空字符串【校验器】
 */
public class StringValidator implements ConstraintValidator<NotBlank, String> {
    @Override
    public void initialize(NotBlank constraintAnnotation) {

    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return value != null && !StringUtils.isBlank(value) && !StringUtils.isEmpty(value.trim());
    }
}
